﻿#pragma warning disable 0436
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Reflection;

namespace System.ComponentModel
{
	internal static class TypeDescriptor
	{
		public const BindingFlags DefaultBindings = BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly;

		public static IEnumerable<PropertyDescriptor> GetProperties(object source)
		{
			Contract.Requires(source != null);
			Contract.Ensures(Contract.Result<IEnumerable<PropertyDescriptor>>() != null);

			return source.GetType().GetProperties(DefaultBindings).Select(property => new PropertyDescriptor(property));
		}

		public static IEnumerable<EventDescriptor> GetEvents(object source)
		{
			Contract.Requires(source != null);
			Contract.Ensures(Contract.Result<IEnumerable<EventDescriptor>>() != null);

			return source.GetType().GetEvents(DefaultBindings).Select(@event => new EventDescriptor(@event));
		}
	}
}